<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加代理设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css" />
  <script src="../mobile/js/jquery-1.9.1.js"></script>
  <script src="../mobile/js/layer/layui.js"></script>
  <script src="./js/common.js"></script>
  <script type="text/javascript">
      //访问是否登录,ajax同步请求
      logins(); 
  </script>
</head>
<body>
<div style="margin: -30px 20px 20px 20px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;cursor: pointer;" onclick="window.location.href='setting_template.html'">
  <legend>代理设置</legend>
</fieldset>
<blockquote class="layui-elem-quote">
   <button class="layui-btn" style="background:#5FB878;" onclick="javascript :history.back(-1);"><i class="layui-icon" style="color: #fff">&#xe65c;</i>返回</button>
   <button class="layui-btn btns"><i class="layui-icon" style="color: #fff">&#xe642;</i>添加代理</button>
</blockquote>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form" method="post">
            <!-- <div class="layui-form-item">
              <label class="layui-form-label">代理</label>
              <div class="layui-input-inline" id="agents1">
                <select name="agent_level"  id="agent1" lay-verify="agent1">
                  <option>一级代理</option>
                </select>
              </div>
            </div> -->
            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-inline">
                <input type="text" name="agent_name" autocomplete="off" placeholder="请输入用户名" class="layui-input" id="agent_name" lay-verify="agent_name">
              </div>
              <div class="layui-form-mid layui-word-aux">用户名不能为空</div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">QQ账号</label>
              <div class="layui-input-inline">
                <input type="text" name="agent_qq" autocomplete="off" placeholder="请输入账号" class="layui-input" id="agent_qq" lay-verify="agent_qq">
              </div>
              <div class="layui-form-mid layui-word-aux">QQ账号</div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">手机号码</label>
              <div class="layui-input-inline">
                <input type="text" name="mobile" autocomplete="off" placeholder="请输入手机号码" class="layui-input" id="mobile" lay-verify="mobile">
              </div>
              <div class="layui-form-mid layui-word-aux">11位数字组成</div>
            </div>
            <!-- <div class="layui-form-item">
              <label class="layui-form-label">佣金比例</label>
              <div class="layui-input-inline">
                <input type="number" name="scale" autocomplete="off" placeholder="请输入佣金比例" class="layui-input" id="scale" style="width: 320px;" lay-verify="scale"  min="0"  step="0.01" required="required">
              </div>
              <div class="layui-form-mid layui-word-aux" style="margin-left: 130px;">比例不能小于0，不能超过2位小数</div>
            </div> -->
            <div class="layui-form-item">
              <label class="layui-form-label">性别</label>
              <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男" lay-verify="sex" checked>
                <input type="radio" name="sex" value="0" lay-verify="sex" title="女">
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button type="submit" class="layui-btn btns" lay-submit="" lay-filter="agentadd">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
        </form>
    </div>
  </div>      
<script>
var aid = "";
var bid = "";
layui.use(['form','layer'], function(){
    var form = layui.form
    ,layer = layui.layer
    ,$ = layui.jquery;


    
    var urls = url+"/admin/device/agent1";
    var urlss = url+"/admin/device/agent2";
    $.get(urls,{},function(msg) {
        $.each(msg.data, function(i, item) {
               $("#agent1").append("<option value='" + item.id + "'>" + item.agent_name + "</option>");
               form.render();
        });
        $('#agents1>div>dl').find('dd').click(function(){
            aid = $(this).attr('lay-value');
        }); 
    },'json');  

    //自定义验证规则
    form.verify({
        agent_name: function(value){
          if(value.length < 1){
            return '用户名不能为空';
          }
        },
        mobile: [/^1[34578][0-9]{9}$/, '手机号码格式错误,请输入11位数字'],
        // scale: function(value){
        //   var reg= /^(-?\d+)(\.\d{1,2})?$/;
        //   if(value < 0  ||  !reg.test(value)){
        //     return '比例不能小于0，不能超过2位小数';
        //   }
        // },
        agent_qq: [/^[1-9][0-9]{4,9}$/, 'QQ号格式有误']
    });
    //监听提交
    form.on('submit(agentadd)', function(data){
      var urls = url + "/admin/agency/agentadds";
      $.post(urls,data.field,function(msg){
          if(msg.code == 1){
            layer.alert(msg.infomsg, {icon: 6},function () {
                window.location.reload();
            });
          }else{
            layer.alert(msg.infomsg, {icon: 5}); 
          }
      },'json')
        return false;
    }); 
});
</script>
</body>
</html>